/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.clase.demo.dao.impl;

import edu.upc.clase.demo.dao.DetalleReservSalaServAdicDao;
import edu.upc.clase.demo.entity.DetalleReservSalaServAdic;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;
/**
 *  private String codDetResSala;
    private String codResSala;
    private String codInst;
    private String codServAdic;
 * @author usuario
 */
@Repository
public class DetalleReservSalaServAdicDaoImpl extends SimpleJdbcDaoSupport 
             implements DetalleReservSalaServAdicDao{
    
  private static Logger log = LoggerFactory.getLogger(DetalleReservSalaServAdicDaoImpl.class);
  
      @Autowired
       public DetalleReservSalaServAdicDaoImpl (DataSource dataSource) {
       log.info("Asignando el dataSource");
       setDataSource(dataSource);    
    }
      @Override
      public Integer insertar(DetalleReservSalaServAdic detalleReservSalaServAdic) {
        getJdbcTemplate().update(
                "insert into Local (codDetResSala,codResSala,codInst,codServAdic)"
                + " values (?, ?, ?, ?)",
                detalleReservSalaServAdic.getCodDetResSala(),
                detalleReservSalaServAdic.getCodResSala(),
                detalleReservSalaServAdic.getCodInst(),
                detalleReservSalaServAdic.getCodServAdic());
        return getSimpleJdbcTemplate().queryForInt("select last_insert_codDetResSala()");
    }
      @Override
      public void actualizar(DetalleReservSalaServAdic detalleReservSalaServAdic) {
        getJdbcTemplate().update(
                "update DetalleReservSalaServAdic set codResSala = ?, codInst = ?, "
                + "codServAdic= ? where codDetResSala = ?",
                detalleReservSalaServAdic.getCodResSala(),
                detalleReservSalaServAdic.getCodInst(),
                detalleReservSalaServAdic.getCodServAdic(), 
                detalleReservSalaServAdic.getCodDetResSala());
    }

    @Override
    public void eliminar(DetalleReservSalaServAdic detalleReservSalaServAdic) {
        getJdbcTemplate().update(
                "delete from DetalleReservSalaServAdic where codDetResSala = ?",
                detalleReservSalaServAdic.getCodDetResSala());
    }
    @Override
    public DetalleReservSalaServAdic buscar(String codDetResSala, String codResSala) {
        try {
            return getSimpleJdbcTemplate().queryForObject(
                    "select codDetResSala,codResSala,codInst,codServAdic"
                    + "from DetalleReservSalaServAdic where codDetResSala=?",
                    new BeanPropertyRowMapper<DetalleReservSalaServAdic>
                    (DetalleReservSalaServAdic.class), codDetResSala,codResSala);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

    @Override
    public List<DetalleReservSalaServAdic> buscarTodos() {
        return getSimpleJdbcTemplate().query(
                "select codDetResSala,codResSala,codInst,codServAdic"
                + "from DetalleReservSalaServAdic",
                new BeanPropertyRowMapper<DetalleReservSalaServAdic>
                (DetalleReservSalaServAdic.class));
    }
}
